import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:toys_flutter/components/MyImageWidget.dart';

class LiveRoomItem extends StatefulWidget {
  final dynamic item;
  const LiveRoomItem({super.key, this.item});

  @override
  State<LiveRoomItem> createState() => _LiveRoomItemState();
}

class _LiveRoomItemState extends State<LiveRoomItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(5),
      margin: const EdgeInsets.all(5),
      child: Stack(
        children: [
          // 动态图片
          _buildImages(widget.item),
          // 状态
          Positioned(
            top: 10,
            left: 10,
            child: TDTag(
              widget.item['live_status_desc'],
              backgroundColor: Colors.red,
              textColor: Colors.white,
              size: TDTagSize.small,
              shape: TDTagShape.round,
            ),
          ),
          // 是否收费
          Positioned(
            top: 10,
            right: 10,
            child: TDTag(
              widget.item['is_gift'] == 1 ? '收费' : '免费',
              backgroundColor: Colors.orange,
              textColor: Colors.white,
              size: TDTagSize.small,
            ),
          ),
          // 名称
          Positioned(
            bottom: 10,
            left: 10,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  widget.item['title'],
                  style: TextStyle(fontSize: 14, color: Colors.white),
                ),
                SizedBox(height: 5,),
                Text(
                  '${widget.item['people']} 人观看',
                  style: TextStyle(fontSize: 12, color: Colors.white),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 动态图
Widget _buildImages(dynamic item) {
  return MyImageWidget(image: item['image'], imageWidth: double.infinity);
}